package com.megvii.koala.tv.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.megvii.corelib.util.ScreenUtil;
import com.megvii.koala.tv.R;

/**
 * Created by linyue on 16/3/15.
 */
public class ScreenTestActivity extends Activity
{
    protected View container;

    protected TextView text1;

    protected TextView text2;

    private int y;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.screen_test_layout);
        container = findViewById(R.id.screen_test_container);
        text1 = (TextView) findViewById(R.id.screen_test_text1);
        text2 = (TextView) findViewById(R.id.screen_test_text2);
    }

    private void updateView()
    {
        String position = "y: " + y;
        text1.setText(position);
        text2.setText(position);
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) container.getLayoutParams();
        params.topMargin = y;
        //        params.width = (int) (width * ScreenUtil.getInstance().screenWidth);
        //        params.height = (int) (height * ScreenUtil.getInstance().screenHeight);
        //        params.leftMargin = (int) (left * ScreenUtil.getInstance().screenWidth);
        //        params.topMargin = (int) (top * ScreenUtil.getInstance().screenHeight);
        container.setLayoutParams(params);
        container.invalidate();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN)
        {
            y++;
            if (y >= ScreenUtil.getInstance().screenHeight)
            {
                y = 0;
            }
            updateView();
            return true;
        }
        else if (keyCode == KeyEvent.KEYCODE_DPAD_UP)
        {
            y--;
            if (y < 0)
            {
                y = ScreenUtil.getInstance().screenHeight - 1;
            }
            updateView();
            return true;
        }
        else
        {
            return super.onKeyDown(keyCode, event);
        }
    }
}
